package com.karry.yl.web.services;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.karry.commons.base.SuperController;
import com.karry.commons.vo.LayTableResponse;
import com.karry.yl.domain.services.RoundsSite;
import com.karry.yl.service.services.RoundsSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("/roundsSite")
public class RoundsSiteController extends SuperController {

    @Autowired
    private RoundsSiteService roundsSiteService;
    @RequestMapping
    public String listUI(){
        return "services/roundssite/list";
    }

    @RequestMapping("/list")
    @ResponseBody
    public LayTableResponse listUI(int page, int limit){
        Page<RoundsSite> itemsPage = roundsSiteService.selectPage(new Page<RoundsSite>(page, limit),new EntityWrapper<RoundsSite>().eq("orgId",currentUser.getOrgId()).eq("deleted",false));
        return new LayTableResponse(itemsPage.getRecords(),itemsPage.getTotal());
    }

    @RequestMapping("/add")
    public String addUI(){
        return "services/roundssite/add";
    }

    @RequestMapping("/save")
    public String save(RoundsSite roundsSite){
        roundsSite.setOrgId(currentUser.getOrgId());
        roundsSiteService.insert(roundsSite);
        return "redirect:/roundsSite";
    }

    @RequestMapping("edit")
    public String editUI(Long id, ModelMap map) {
        RoundsSite roundsSite = roundsSiteService.selectById(id);
        map.put("roundsSiteModel", roundsSite);
        return "services/roundssite/edit";
    }

    @RequestMapping("/update")
    public String update(RoundsSite roundsSite){
        roundsSite.setOrgId(currentUser.getOrgId());
        roundsSiteService.updateById(roundsSite);
        return "redirect:/roundsSite";
    }
    /**
     * 删除
     *
     * @param
     * @return
     */
    @RequestMapping(path = "/delete")
    public String delete(@RequestParam("id") List<Long> ids) {
        roundsSiteService.deleteBatchIds(ids);
        return "redirect:/roundsSite";
    }
}
